<?php

namespace app\api\controller\service;

use app\common\controller\Api;

/**
 * 首页接口
 */
class Category extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 获取分类
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getList()
    {
        $type = input('type','');
        $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>0])->order('weigh desc')->select();
        if($type == 'all'){
            foreach ($list as &$val){
                $val['children'] = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>$val['id']])->order('weigh desc')->select();
            }
        }
        $this->success('分类信息返回成功',$list);
    }


    public function getSon()
    {
        $id = input('id/d','');
        $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>$id])->order('weigh desc')->select();
        $this->success('信息返回成功',$list);
    }



}